/**
 *获得页面控件显示并添加到Datawrapper中的帮助方法
 * @function
 * @static
 * @param {zxt.data.DataWrapper}  dw DataWrapper对象
 */
zxt.help.addComponetLabel = function(dw) {
	var comps = $zxt.components();
	var components = {};
	for ( var v in comps) {
		var comp = comps[v];
		if (comp.instanceOf(zxt.ui.AbstractSelect)) {
			components[v] = comp.getLabel();
		} else if (comp.instanceOf(zxt.ui.Interactor)) {
			components[v] = comp.getValue();
		};
	};
	dw.components(components);
};

/**
 *获得列表中的DataSheet对象
 * @function
 * @static
 * @param {zxt.data.CVSTableModel} tmodel 与列表关联的model对象
 * @param {zxt.ui.GridBase} grid  列表对象
 * @return {zxt.data.DataSheet} DataSheet对象
 */
zxt.help.getGridSheet = function (tmodel,grid){
	var sheet = new zxt.data.DataSheet("result");
	sheet.sheetMeta(tmodel.sheetMetas());
	
	var data = grid.gridData();	
	if (tmodel.instanceOf(zxt.data.CVSTableModel)){
		data = tmodel.cached();
	};	

	for(var i=0;i<data.length;i++){
		var row = sheet.getMappedArray(data[i]);
		sheet.addRow(row);
	};
	return sheet;
};

/**
 * 将列表中的所有数据拼成字符串
 * @function
 * @static
 * @param {zxt.ui.GridBase} grid  列表对象
 * @return {string} 内容组成的字符串
 */
zxt.help.getGridString = function(grid) {
	var rowCount = grid.getRowCount();

	var strings = "";
	for ( var i = 0; i < rowCount; i++) {
		var rowData = grid.getRowData(i);
		for ( var x in rowData)
			if (!grid.getColumn(x).hidden())
				strings += rowData[x];
	}
	return strings;
};

/**
 * 将Tab键的顺序列表复制进剪切板
 * @function
 * @static
 * @param {zxt.data.DataWrapper}  dw DataWrapper对象 在函数中没有用到
 */
zxt.help.copyOrder = function(dw) {
	var str = $zxt._rorder.toString();
	clipboardData.setData('text', str);
};

/**
 * 检查页面控件ID与prop文件的对应
 * @function
 * @static
 */
zxt.help.checkPage = function(c) {
	zxt.help._checkWidgetEnum();
	zxt.help._checkWidgetId();
}

/**
 * 检查页面控件ID与prop文件的对应
 * @function
 * @private
 */
zxt.help._checkWidgetEnum = function(c) {
	var p = c || $zxt;
	var getID = function(co) {
		var idstr = "";
		for(var key in $zxtUI){
			if($zxtUI[key].instanceOf(zxt.ui.Composite) || $zxtUI[key].instanceOf(zxt.ui.Hidden) ||  $zxtUI[key].instanceOf(zxt.ui.Button) || $zxtUI[key].instanceOf(zxt.ui.Tree)){
				continue;
			}
			idstr += key + ",";
		}
		if (idstr.length - 1 < 0) {
			return "";
		}
		return idstr.substring(0, idstr.length - 1);
	};
	var getProID = function() {
		var idstr = "";
		var url = "./" + $zxt.PAGE + "_cn.properties";
		var bundle = new zxt.i18n.Bundle(url);
		var ret = bundle.entries();
		var reg = /\$\w*/;
		for ( var key in ret) {
			if (reg.test(key) && (key != "$LIST")) {
				idstr += ret[key] + ",";
			}
		}
		if (idstr.length - 1 < 0) {
			return "";
		}
		return idstr.substring(0, idstr.length - 1);
	};
	var callback = {
		onSuccess : function(ei) {

		},
		onFailure : function(xmlR, status, e) {

		}
	};
	var param = getID(p);
	var proIDs = getProID();
	var dw = new zxt.data.DataWrapper();
	dw.set("components", param);
	dw.set("proIDs", proIDs);
	dw.set("page", $zxt.PAGE);
	EiCommunicator.send("GETID", "checkEnum", dw, callback, false);

};

/**
 * 检查页面控件ID与prop文件的对应
 * @function
 * @private
 */
zxt.help._checkWidgetId = function(c) {
	var KEEP_WIDGETS = "Collect;Clear;Update;Query;aPager;error;refuse;approve;manager_account;manager_pw;confirmButton;resetButton;BNKNBR;ovrid_sync;ovrid_asyn;ovrid_def_old;SRC_OPE_NO;SRC_ACTION;SRC_TRXTYPE;TCHK_SEQ;isOperationAuthorized;ovrid_sync_bak;ovrid_asyn_bak;ovrid_def_bak;collect_menuDirId;collect_oriGroupName;CollectConfirm;CollectReset;undopt1;okpt1;DownLoad1;PTChoose;undopt2;okpt;";
	
	var p = c || $zxt;
	var callback = {
			onSuccess : function(ei) {

			},
			onFailure : function(xmlR, status, e) {

			}
		};
	var getkeys = function() {
		var idstr = "";
		var url = "./" + $zxt.PAGE + "_cn.properties";
		var bundle = new zxt.i18n.Bundle(url);
		var ret = bundle.entries();
		var reg = /\$\w*/;
		for ( var key in ret) {
			if (!reg.test(key)) {
				idstr+=key+";";
			}
		}
		return idstr;
	};
	
	var getID = function(co) {
		var idstr = "";
		for(var key in $zxtUI){
			if($zxtUI[key].instanceOf(zxt.ui.Composite) || $zxtUI[key].instanceOf(zxt.ui.Hidden) || $zxtUI[key].instanceOf(zxt.ui.Button) || $zxtUI[key].instanceOf(zxt.ui.Tree)){
				continue;
			}
			idstr += key + ",";
		}
		if (idstr.length - 1 < 0) {
			return "";
		}
		return idstr.substring(0, idstr.length - 1);
	};
	var param = getkeys();

	var result = "";
	var children = getID(p).split(",");
	for ( var i = 0; i != children.length; i++) {
		if(param.match(children[i])==null){
			if (KEEP_WIDGETS.match(children[i])==null){
				result+=children[i]+";";
			}
		}
	}
	var dw = new zxt.data.DataWrapper();
	dw.set("result", result);
	dw.set("page", $zxt.PAGE);
	EiCommunicator.send("GETID", "checkId", dw, callback, false);
};
